package com.ubs.training.server.service;

import com.ubs.training.prod.server.service.LoggingService;
import com.ubs.training.server.dao.RatingDao;
import com.ubs.training.server.dao.model.Rating;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class RatingService {

    public static final String USER_REQUESTED_RATINGS_FOR_A_CLIENT = "User requested ratings for a client";
    public static final String USER_UPDATED_RATING = "User updated a rating";

    @Resource(name="hbmRatingDao")
    RatingDao dao;


    public RatingDao getDao() {
        return dao;
    }

    public void setDao(RatingDao dao) {
        this.dao = dao;
    }

    public Rating getById(int id)
    {
        return dao.getById(id);

    }
    public List<Rating> getAllRatingsByID(int clientID) {
        return dao.getByClientID(clientID);
    }

    public void saveRating(Rating rating){
        if(rating.getRatingID() == 0){

            dao.add(rating);
        }
        else{

            dao.update(rating);
        }
    }

    public void deleteRating(Rating rating){
        dao.delete(rating);
    }
}
